package com.zj.service;

import com.zj.study.MyApplicationEvent;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Random;

@Service
@Transactional
public class UserService implements IuserService{

    @Autowired
    private ApplicationEventPublisher myPublisher;


    public int deleteUser(Integer id) {

        System.out.println("delete");
        return 1;
    }
    public int updateUser(User user) {
        System.out.println("update");
        return 1;
    }
    public User selectUser(Integer id) {
        System.out.println("select"+Thread.currentThread().getName());
//        int a=1/0;
//        myPublisher.publishEvent(new MyApplicationEvent("selectUser"));
        return new User("zhangsan",id,"女");
    }


    public int addUser(User user) {
        System.out.println("addUser");
        myPublisher.publishEvent(new MyApplicationEvent("addUser"));

        return 1;
    }

}
